<?php 
class Builder_model extends CI_Model
{
	var $active_class = '';
	
	function __construct()
	{
		parent::__construct();
	}
	
	public function getHeaderParams()
	{
		$data = array();
		$data['site_title'] = $this->db->get("site")->row()->title;
		$data['meta_description'] = $this->db->get("site")->row()->meta_description;
		$data['meta_keywords'] = $this->db->get("site")->row()->meta_keywords;
		// FOR NOW WE CHOOSE MAIN NAVIAGTION
		$url_alias = $this->uri->segment(1);
		
		$data['main-nav'] =  $this->db->get_where("menu_items", array("menu_id" => 1 ))->result_array();
		
		// IF URL alias is found
		if($url_alias)
		{
			// WHICH ITEM IS ACTIVE?
			for($i = 0; $i < count($data['main-nav']); $i++)
			{
				$menu_item_id = $data['main-nav'][$i]['id'];
				$check_exist = $this->db->get_where("menu_items", array("alias" => $url_alias, "id" => $menu_item_id,  ))->num_rows() > 0;
				if($check_exist)
				{
					$data['main-nav'][$i]['active_class'] = "class='active'";
				}
				else {
					$data['main-nav'][$i]['active_class'] = "class=''";
				}
			}
		}
		else
		{
			for($i = 0; $i < count($data['main-nav']); $i++)
			{
				// FIRST ITEM LIKELY TO BE HOME ITEM
				$data['main-nav'][0]['active_class'] = "class='home active'";
				if($i > 0)
				{
					$data['main-nav'][$i]['active_class'] = "";
				}
			}
		}
		
		return $data;
	}
	public function getFrontPageParams()
	{
		$data = array();
		$query = $this->db->get_where("articles", array("is_frontpage" => "1"));
		if($query->num_rows() > 0)
		{
			$data["article:fulltext"] = $query->row()->fulltext;
			$data["article:title"] = $query->row()->title;
			return $data;
		}
		return $data;
	}
}
?>